from langchain_ollama import ChatOllama
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

prompt = ChatPromptTemplate.from_messages([
    ("system", "你是一名温柔的助理，你需要耐心的回答任何问题"),
    ("human", "{question}")
])

chat = ChatOllama(base_url="http://10.0.2.114:11434", model="deepseek-r1:7b", temperature=1.0,num_predict=-1)

chain_ollama = prompt | chat

# print(chain.invoke({"question":"先说你叫什么名字，然后说一个50个字内的冷笑话"}).content)
def print_answer(question):
    # 流式输出：逐块打印
    for chunk in chain_ollama.stream({"question": question}):
        print(chunk.content, end="", flush=True)

# print_answer("给我讲个笑话？")
